//
//  ByLoginVC.m
//  Homept_ios
//
//  Created by pro on 16/9/1.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ByLoginVC.h"
#import "ByLoginUserOperationView.h"
@interface ByLoginVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)ByLoginUserOperationView *userView;
@end

@implementation ByLoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([self.fromVC isEqualToString:@"1"]) {
        
    }else{
        [self addLeftBackBarButtonItem];
    }
    [self createUserView];
    [self initTableview];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gettext:) name:@"registermodel" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gettext:) name:@"findpswmodel" object:nil];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // 隐藏标签栏
    ByTabBarController *main = (ByTabBarController *)self.navigationController.tabBarController;
    [main hideTabBar];
}
- (void)gettext:(NSNotification *)text {
    NSDictionary *dic = text.userInfo;
    ByTextField *phonefiled = (ByTextField *)[_userView viewWithTag:10];
    ByTextField *pwdfiled = (ByTextField *)[_userView viewWithTag:11];
    phonefiled.text = dic[@"phone"];
    pwdfiled.text = dic[@"psw"];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"registermodel" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"findpswmodel" object:nil];
}
#pragma mark ---创建视图
- (void)initTableview{
    _tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    [self.view addSubview:_tableview];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.allowsSelection = NO;
    _tableview.showsVerticalScrollIndicator = NO;
    _tableview.delegate = self;
    _tableview.dataSource = self;
}
- (void)createUserView{
    _userView = [[ByLoginUserOperationView  alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 140 + 45 + 40 + LineHeight*2) Titles:@[@"输入手机号",@"输入密码"] ImageAry:@[@"login_account",@"login_password"]];
    if (self.phoneStr.length > 0 && self.passwordStr.length > 0) {
        ByTextField *phonefiled = (ByTextField *)[_userView viewWithTag:10];
        ByTextField *pwdfiled = (ByTextField *)[_userView viewWithTag:11];
        phonefiled.text = self.phoneStr;
        pwdfiled.text = self.passwordStr;
    }
}
#pragma mark ---UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    [cell addSubview:_userView];
    cell.backgroundColor = [UIColor yellowColor];
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return LineHeight*2 + 140 + 45 + 40;
    
}

@end
